package com.yitong.qicenter.activity;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.yitong.qicenter.R;


public class WelcomeActivity extends Activity implements View.OnClickListener {
    private TextView tv_version;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        hideNavigationBar();//隐藏导航栏
        initView();
        initData();
        //延时跳转到主页面
        delayedJumpMainPage();
    }

    private void initData() {
        //设置版本号
        setVersion();
    }

    //设置版本号
    private void setVersion() {
        tv_version.setText("v:" + getLocalVersionName(WelcomeActivity.this));
    }

    private void initView() {
        setContentView(R.layout.activity_welcome);
        tv_version = (TextView) findViewById(R.id.tv_version);

    }

    //延时跳转到主页面
    private void delayedJumpMainPage() {

        Handler handler = new Handler();
        //当计时结束,跳转至主界面
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                //跳转到登录页面
                Intent it = new Intent(WelcomeActivity.this, MainActivity.class);
                startActivity(it);
                finish();
            }
        }, 2000);
    }

    //隐藏导航栏
    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    @SuppressLint("InlinedApi")
    public void hideNavigationBar() {
        int uiFlags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
                View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |// 隐藏导航栏
                View.SYSTEM_UI_FLAG_FULLSCREEN | // 隐藏状态栏
                View.SYSTEM_UI_FLAG_IMMERSIVE;
        if (Build.VERSION.SDK_INT >= 19) {
            uiFlags |= 0x00001000;
        } else {
            uiFlags |= View.SYSTEM_UI_FLAG_LOW_PROFILE;
        }
        getWindow().getDecorView().setSystemUiVisibility(uiFlags);
    }

    /**
     * 获取本地软件版本号名称
     */
    public static String getLocalVersionName(Context ctx) {
        String localVersion = "";
        try {
            PackageInfo packageInfo = ctx.getApplicationContext()
                    .getPackageManager()
                    .getPackageInfo(ctx.getPackageName(), 0);
            localVersion = packageInfo.versionName;

        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return localVersion;
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {

        }
    }
}
